package gui.commons;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class TextPanel extends JPanel {
	
	/*
	 *	Variables declaration
	 *
	 * */
	private JTextArea ta;
	Dimension dim = getPreferredSize(); 
			
	public TextPanel() {
		/*
		 * Initializing variables
		 * 
		 * */
		ta = new JTextArea();
		
		/*
		 *	setting layout for the TextPanel
		 *
		 */
		//	TextPanel will be used as a log window. Therefore, it needs not that much space.
		dim.height = 100;
		setPreferredSize(dim);
		
		setLayout(new BorderLayout());
		
		/*
		 *	Adding components to the TextPanel
		 * 
		 * */
		//	adding textArea 'ta' contained by an scrollable pane
		add(new JScrollPane(ta), BorderLayout.CENTER);
		
	}
	
	public void txpAppend(String str) {
		ta.append(str);
	}
	
	public void tpClearAll() {
		try {
			String tmp = ta.getSelectedText();
			System.out.println("tpClearAll: " + tmp);
			ta.setText(tmp);
		} catch (NullPointerException npe){
			System.out.println("NPE: " + npe);
			//npe.printStackTrace();
		}
		
	}
}
